<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        function _ajaxTool(method, url, data, cd) {
            let xhr = new XMLHttpRequest();
            if (method == "GET") {
                let a = '';
                for (let key in data) {
                    a += `${key}=${data[key]}&`;
                };
                let newUrl = `${url}?${a.slice(0,-1)}.`;
                console.log(newUrl);
                xhr.open(method, newUrl);
                xhr.send();
            } else {
                let postData = '';
                xhr.open(method, url);
                xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
                for (let key in data) {
                    postData += `${key}=${data[key]}&`
                }
                postData = postData.slice(0, -1);
                xhr.send(postData)
            }
            xhr.addEventListener('readystatechange', function() {
                if (xhr.readyState == 4) {
                    if (xhr.status == 200) {
                        cd(JSON.parse(xhr.responseText))
                    }
                }
            });
        }

        let posturl = `http://newshopapi.0melon0.cn/api/f_user/register`;

        let postData = {
            name: "都是",
            phone: "15423242322",
            card: "231311313131341",
        }

        _ajaxTool("POST", posturl, postData, function(data) {
            console.log(data);
        })
    </script>
</body>

</html>